#include <cstdio>
#include <cstring>
#include <algorithm>
#include <unistd.h>
using namespace std;
struct UTF8_C
{
	int len;
	unsigned char data[7];
	UTF8_C(){}
	UTF8_C( const char * s )
	{
		for( len = 0 ; data[len] = s[len] ; len ++ );
	}
	bool operator == ( UTF8_C& b)
	{
		if( len != b.len ) return false;
		for( int i = 0 ; i < len ; i ++ )
			if( data[i] != b.data[i] )
				return false;
		return true;
	}
};

UTF8_C cao("草");
UTF8_C ni("泥");
UTF8_C ma("马");
UTF8_C da("大");
UTF8_C ye("爷");
UTF8_C quan("全");
UTF8_C jia("家");
UTF8_C chao("朝");
UTF8_C he("河");
UTF8_C xie("蟹");
UTF8_C zu("祖");
UTF8_C zong("宗");
UTF8_C hen("很");
UTF8_C fei("非");
UTF8_C chang("常");
UTF8_C jiong("囧");
UTF8_C cao2("操");
UTF8_C cao3("肏");
UTF8_C ni2("你");
UTF8_C ma2("妈");
UTF8_C shui("水");
UTF8_C chan("产");
UTF8_C bi("比");
UTF8_C wo("卧");
FILE *fin , *fout;
UTF8_C* charset[] = { &cao , &cao2 , &cao3 ,
		      &ni , &ni2 , 
		      &ma , &ma2,
		      &da ,
		      &ye,
		      &quan,
		      &jia,
		      &chao,
		      &he,
		      &xie,
		      &zu,
		      &zong,
		      &fei,
		      &chang,
		      &hen,
		      &jiong,
		      &shui,
		      &chan,
		      &bi,
		      &wo};
int getchar( FILE* fp , UTF8_C& buf )
{
	buf.len = 1;
	if(feof(fp)) return EOF;
	fread( buf.data , 1 , 1 , fp );
	if(buf.data[0]>=0x80)
		for( char temp = buf.data[0]<<1 ; temp < 0 ; temp <<= 1 )
			fread( buf.data + (buf.len++) , 1 , 1 ,fp );
	return buf.len;
}
int in_charset(  UTF8_C & c )
{
	for( int i = 0 ; i < 24 ; i ++ )
		if( c == *charset[i] )
			return true;
	return false;
}
int next_char( FILE* fin , UTF8_C& buf )
{
	buf.len = -1;
	for( ; getchar( fin , buf )!= EOF && !in_charset(buf););
	return buf.len;
}
int parse_value( FILE* fin)
{
	UTF8_C t;
	int ret = 0;
	while( next_char( fin , t ) != -1 )
	{
		if( t == jiong )
			return ret;
		else if( t == hen )
			ret = ret * 2;
		else if( t == fei )
		{
			int r = next_char( fin , t );
			if( r != -1 && t == chang )
				ret = ret * 2 + 1 ;
			else 
			{
				fprintf( stderr , "你会不会写程序啊...非常囧\n");
				exit(0);
			}
		}
		else
		{
			fprintf( stderr , "你会不会写程序啊...非常囧\n");
			exit(0);
		}
		
	}
	return ret;
}

int main(int argc,char** argv)
{
	if( argc ==1 ) 
	{
		printf("usage: cnmc outfile [infile]\n");
		return 0;
	}
	
	if( argc > 1 ) fout = fopen( "temp.c" , "wb"); else fout = stdout;
	if( argc > 2 ) fin =  fopen( argv[2] , "rb"); else fin = stdin;
	//fout = stdout;
	fputs("#include \"stdio.h\"\n",fout);
	fputs("#include \"stdlib.h\"\n",fout);
	fputs("int stack[10000];\n",fout);
	fputs("int reg;\n",fout);
	fputs("int sp = 0;\n",fout);
	fputs("void push(int v){stack[sp++]=v;}\n",fout);
	fputs("void pop (){sp--;}\n",fout);
	fputs("int getval(){int ret;scanf(\"%d\",&ret);return ret;}\n",fout);
	fputs("int alu(int id){\nif(id==0) stack[sp-2]+=stack[sp-1];\nif(id==1) stack[sp-2]-=stack[sp-1];\nif(id==2) stack[sp-2]*=stack[sp-1];\nif(id==3) stack[sp-2]/=stack[sp-1];\nsp--;\n}\n",fout);
	fputs("int main(){\n",fout);
	UTF8_C buf;
	while(!feof(fin))
	{
		next_char( fin , buf );
		if( buf == cao || buf == cao2 || buf == cao3)
			fprintf(fout,"push(%d);\n",parse_value(fin));
		else if( buf == ni || buf == ni2 )
			fprintf(fout,"pop();\n");
		else if( buf == ma )
			fprintf(fout,"alu(%d);\n",parse_value(fin));
		else if( buf == he )
		{
			if( next_char( fin , buf ) == EOF )
			{
				fprintf( stderr , "怎么这就完了？\n");
				exit(0);
			}
			if( buf == xie )
				fprintf(fout,"push(reg);\n");
			else
			{
				fprintf( stderr , "你要说的是？河蟹？？\n");
				exit(0);
			}
		}
		else if( buf == shui )
		{
			if( next_char( fin , buf ) == EOF )
			{
				fprintf( stderr , "怎么这就完了？\n");
				exit(0);
			}
			if( buf == chan )
				fprintf(fout,"reg=stack[sp-1];\n");
			else
			{
				fprintf( stderr , "你要说的是？水产？？\n");
				exit(0);
			}
		}
		else if( buf == zu )
		{
			if( next_char( fin , buf ) == EOF )
			{
				fprintf( stderr , "怎么这就完了？\n");
				exit(0);
			}
			if( buf == zong )
				fprintf(fout,"LL%d:\n",parse_value(fin));
			else
			{
				fprintf( stderr , "你要说的是？祖宗？？\n");
				exit(0);
			}
		}
		else if( buf == wo )
		{
			if( next_char( fin , buf ) == EOF )
			{
				fprintf( stderr , "怎么这就完了？\n");
				exit(0);
			}
			if( buf == cao )
				fprintf(fout,"if(stack[sp-1])goto LL%d;\n",parse_value(fin));
			else
			{
				fprintf( stderr , "你要说的是？卧草？？\n");
				exit(0);
			}
		}
		else if( buf == chao )
		{
			if( next_char( fin , buf ) == EOF )
			{
				fprintf( stderr , "怎么这就完了？\n");
				exit(0);
			}
			if( buf == ni )
			{
				UTF8_C tt;
				if( next_char( fin , buf ) == EOF )
				{
					fprintf( stderr , "怎么这就完了？\n");
					exit(0);
				}
				if( next_char( fin , tt ) == EOF )
				{
					fprintf( stderr , "怎么这就完了？\n");
					exit(0);
				}
				if( buf == zu && tt == zong )
					fprintf( fout , "push(getchar());\n");
				else if( buf == ma && tt == bi )
					fprintf( fout , "push(getval());\n");
				else if( buf == quan && tt == jia )
					fprintf( fout , "printf(\"%cd\",stack[sp-1]);\n",'%');
				else if( buf == da && tt == ye )
					fprintf( fout , "printf(\"\%cc\",stack[sp-1]);\n",'%');
				else
				{
					fprintf( stderr , "你要朝泥什么？\n");
					exit(0);
				}			
			}
			else
			{
				fprintf( stderr , "你要说的是？朝尼？？\n");
				exit(0);
			}
		}
		
	}
	fprintf( fout , "return stack[sp-1];\n}\n");
	fclose(fout);
	char* args[] = {"gcc","temp.c","-o",argv[1],NULL};
	execvp("gcc",args);
	return 0;
}

